"""
流量渠道模型
"""
from sqlalchemy import Column, String, Text, Enum, DateTime, func
from sqlalchemy.orm import relationship
from .base import Base


class TrafficChannel(Base):
    """流量渠道表"""
    __tablename__ = "traffic_channels"
    
    name = Column(String(50), nullable=False, comment="渠道名称")
    type = Column(Enum("internal", "external", name="channel_type"), 
                 default="external", comment="渠道类型：内部/外部")
    description = Column(Text, comment="渠道描述")
    
    # 关系
    students = relationship("Student", back_populates="traffic_channel")
    traffic_allocations = relationship("TrafficAllocation", back_populates="traffic_channel")
    traffic_statistics = relationship("TrafficStatistics", back_populates="traffic_channel")
    
    def __repr__(self):
        return f"<TrafficChannel(id={self.id}, name='{self.name}', type='{self.type}')>"
